﻿using SD.Infrastructure.EntityBase;
using System;
using System.Text;

namespace SlamDunk.MES.Domain.Entities.MaintenanceContext
{
    /// <summary>
    /// 设备维护记录
    /// </summary>
    public class EquipmentMaintenance : AggregateRootEntity
    {
        #region # 构造器

        #region 00.无参构造器
        /// <summary>
        /// 无参构造器
        /// </summary>
        protected EquipmentMaintenance() { }
        #endregion

        #region 01.创建设备维护记录构造器
        /// <summary>
        /// 创建设备维护记录构造器
        /// </summary>
        /// <param name="maintenanceNo">维护记录编号</param>
        /// <param name="maintenanceName">维护记录名称</param>
        /// <param name="equipmentMaintainClassId">设备维护类Id</param>
        /// <param name="equipmentId">设备Id</param>
        /// <param name="equipmentAssetId">设备资产Id</param>
        /// <param name="maintainedDate">维护日期</param>
        /// <param name="maintainedHour">维护工时</param>
        /// <param name="maintainedParts">维护部位</param>
        /// <param name="maintainedContent">维护内容</param>
        /// <param name="sparePartsUse">备件使用</param>
        /// <param name="maintainer">维护人</param>
        /// <param name="facilityId">工厂模型Id</param>
        /// <param name="description">描述</param>
        public EquipmentMaintenance(string maintenanceNo, string maintenanceName, Guid equipmentMaintainClassId, Guid equipmentId, Guid equipmentAssetId, DateTime maintainedDate, decimal? maintainedHour, string maintainedParts, string maintainedContent, string sparePartsUse, string maintainer, Guid? facilityId, string description)
            : this()
        {
            base.Number = maintenanceNo;
            base.Name = maintenanceName;
            this.EquipmentMaintainClassId = equipmentMaintainClassId;
            this.EquipmentId = equipmentId;
            this.EquipmentAssetId = equipmentAssetId;
            this.MaintainedDate = maintainedDate;
            this.MaintainedHour = maintainedHour;
            this.MaintainedParts = maintainedParts;
            this.MaintainedContent = maintainedContent;
            this.SparePartsUse = sparePartsUse;
            this.Maintainer = maintainer;
            this.FacilityId = facilityId;
            this.Description = description;

            //初始化关键字
            this.InitKeywords();
        }
        #endregion

        #endregion

        #region # 属性

        #region 设备维护类Id —— Guid EquipmentMaintainClassId
        /// <summary>
        /// 设备维护类Id
        /// </summary>
        public Guid EquipmentMaintainClassId { get; private set; }
        #endregion

        #region 设备Id —— Guid EquipmentId
        /// <summary>
        /// 设备Id
        /// </summary>
        public Guid EquipmentId { get; private set; }
        #endregion

        #region 设备资产Id —— Guid EquipmentAssetId
        /// <summary>
        /// 设备资产Id
        /// </summary>
        public Guid EquipmentAssetId { get; private set; }
        #endregion

        #region 维护日期 —— DateTime MaintainedDate
        /// <summary>
        /// 维护日期
        /// </summary>
        public DateTime MaintainedDate { get; private set; }
        #endregion

        #region 维护工时 —— decimal? MaintainedHour
        /// <summary>
        /// 维护工时
        /// </summary>
        public decimal? MaintainedHour { get; private set; }
        #endregion

        #region 维护部位 —— string MaintainedParts
        /// <summary>
        /// 维护部位
        /// </summary>
        public string MaintainedParts { get; private set; }
        #endregion

        #region 维护内容 —— string MaintainedContent
        /// <summary>
        /// 维护内容
        /// </summary>
        public string MaintainedContent { get; private set; }
        #endregion

        #region 备件使用 —— string SparePartsUse
        /// <summary>
        /// 备件使用
        /// </summary>
        public string SparePartsUse { get; private set; }
        #endregion

        #region 维护人 —— string Maintainer
        /// <summary>
        /// 维护人
        /// </summary>
        public string Maintainer { get; private set; }
        #endregion

        #region 工厂模型Id —— Guid? FacilityId 
        /// <summary>
        /// 工厂模型Id
        /// </summary>
        public Guid? FacilityId { get; private set; }
        #endregion

        #region 描述 —— string Description
        /// <summary>
        /// 描述
        /// </summary>
        public string Description { get; private set; }
        #endregion

        #endregion

        #region # 方法

        #region 修改设备维护记录 —— void UpdateInfo(DateTime maintainedDate...
        /// <summary>
        /// 修改设备维护记录
        /// </summary>
        /// <param name="maintainedDate">维护日期</param>
        /// <param name="maintainedHour">维护工时</param>
        /// <param name="maintainedParts">维护部位</param>
        /// <param name="maintainedContent">维护内容</param>
        /// <param name="sparePartsUse">备件使用</param>
        /// <param name="maintainer">维护人</param>
        /// <param name="facilityId">工厂模型Id</param>
        /// <param name="description">描述</param>
        public void UpdateInfo(DateTime maintainedDate, decimal? maintainedHour, string maintainedParts, string maintainedContent, string sparePartsUse, string maintainer, Guid? facilityId, string description)
        {
            this.MaintainedDate = maintainedDate;
            this.MaintainedHour = maintainedHour;
            this.MaintainedParts = maintainedParts;
            this.MaintainedContent = maintainedContent;
            this.SparePartsUse = sparePartsUse;
            this.Maintainer = maintainer;
            this.FacilityId = facilityId;
            this.Description = description;

            //初始化关键字
            this.InitKeywords();
        }
        #endregion

        #region 初始化关键字 —— void InitKeywords()
        /// <summary>
        /// 初始化关键字
        /// </summary>
        private void InitKeywords()
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(base.Number);
            builder.Append(base.Name);
            builder.Append(this.MaintainedParts);
            builder.Append(this.MaintainedContent);
            builder.Append(this.SparePartsUse);
            builder.Append(this.Maintainer);
            builder.Append(this.Description);

            base.SetKeywords(builder.ToString());
        }
        #endregion

        #endregion
    }
}
